# Contributor: Mehdi Chinoune <mehdi.chinoune@hotmail.com>

_realname=Vulkan-Utility-Libraries
pkgbase=mingw-w64-vulkan-utility-libraries
pkgname=("${MINGW_PACKAGE_PREFIX}-vulkan-utility-libraries")
pkgver=1.4.313.0
pkgrel=1
pkgdesc='Libraries for Vulkan developers (mingw-w64)'
arch=('any')
mingw_arch=('mingw64' 'ucrt64' 'clang64' 'clangarm64')
url="https://www.khronos.org/vulkan/"
msys2_repository_url="https://github.com/KhronosGroup/Vulkan-Utility-Libraries"
license=('spdx:Apache-2.0')
groups=("${MINGW_PACKAGE_PREFIX}-vulkan-devel")
makedepends=("${MINGW_PACKAGE_PREFIX}-cc"
             "${MINGW_PACKAGE_PREFIX}-cmake"
             "${MINGW_PACKAGE_PREFIX}-ninja"
             "${MINGW_PACKAGE_PREFIX}-vulkan-headers")
conflicts=("${MINGW_PACKAGE_PREFIX}-vulkan-validation-layers<1.3.268")
source=("https://github.com/KhronosGroup/${_realname}/archive/vulkan-sdk-${pkgver}/${_realname}-${pkgver}.tar.gz")
sha256sums=('3e04f32c6023997c153ad4b63e2fd344257e40a57ff5229ab7373e08a4fa2dd2')

build() {
  mkdir -p "${srcdir}"/build-${MSYSTEM} && cd "${srcdir}"/build-${MSYSTEM}

  declare -a extra_config
  if check_option "debug" "n"; then
    extra_config+=("-DCMAKE_BUILD_TYPE=Release")
  else
    extra_config+=("-DCMAKE_BUILD_TYPE=Debug")
  fi

  MSYS2_ARG_CONV_EXCL="-DCMAKE_INSTALL_PREFIX=" \
  ${MINGW_PREFIX}/bin/cmake.exe \
    -G "Ninja" \
    "${extra_config[@]}" \
    -DCMAKE_INSTALL_PREFIX=${MINGW_PREFIX} \
    -DBUILD_TESTS=OFF \
    -DVUL_WERROR=OFF \
    ../${_realname}-vulkan-sdk-${pkgver}

  ${MINGW_PREFIX}/bin/cmake.exe --build .
}

package() {
  cd "${srcdir}"/build-${MSYSTEM}
  DESTDIR="${pkgdir}" ${MINGW_PREFIX}/bin/cmake.exe --install .

  install -Dm644 "${srcdir}"/${_realname}-vulkan-sdk-${pkgver}/LICENSE.md "${pkgdir}"${MINGW_PREFIX}/share/licenses/vulkan-utility-libraries/LICENSE
}
